#coding=utf-8
#Boa:Dialog:DlgEditorContact

import wx

from product import CDataCustomerContact

def create(parent):
    return DlgEditorContact(parent)

[wxID_DLGEDITORCONTACT, wxID_DLGEDITORCONTACTBTNCANCEL, 
 wxID_DLGEDITORCONTACTBTNOK, wxID_DLGEDITORCONTACTTCMEMO, 
 wxID_DLGEDITORCONTACTTCNAME, wxID_DLGEDITORCONTACTTCPHONE, 
 wxID_DLGEDITORCONTACTTMEMO, wxID_DLGEDITORCONTACTTNAME, 
 wxID_DLGEDITORCONTACTTPHONE, 
] = [wx.NewId() for _init_ctrls in range(9)]

class DlgEditorContact(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGEDITORCONTACT,
              name=u'DlgEditorContact', parent=prnt, pos=wx.Point(382, 210),
              size=wx.Size(557, 415), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u7f16\u8f91\u8054\u7cfb\u4eba')
        self.SetClientSize(wx.Size(549, 381))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.tName = wx.StaticText(id=wxID_DLGEDITORCONTACTTNAME,
              label=u'\u8054\u7cfb\u4eba\u540d\u79f0\uff1a', name=u'tName',
              parent=self, pos=wx.Point(56, 40), size=wx.Size(104, 14),
              style=0)

        self.tcName = wx.TextCtrl(id=wxID_DLGEDITORCONTACTTCNAME,
              name=u'tcName', parent=self, pos=wx.Point(160, 32),
              size=wx.Size(184, 22), style=0, value=u'')

        self.tPhone = wx.StaticText(id=wxID_DLGEDITORCONTACTTPHONE,
              label=u'\u8054\u7cfb\u4eba\u7535\u8bdd\uff1a', name=u'tPhone',
              parent=self, pos=wx.Point(56, 80), size=wx.Size(104, 14),
              style=0)

        self.tcPhone = wx.TextCtrl(id=wxID_DLGEDITORCONTACTTCPHONE,
              name=u'tcPhone', parent=self, pos=wx.Point(160, 72),
              size=wx.Size(184, 22), style=0, value=u'')

        self.tMemo = wx.StaticText(id=wxID_DLGEDITORCONTACTTMEMO,
              label=u'\u5907\u6ce8  \u4fe1\u606f\uff1a', name=u'tMemo',
              parent=self, pos=wx.Point(56, 120), size=wx.Size(103, 16),
              style=0)

        self.tcMemo = wx.TextCtrl(id=wxID_DLGEDITORCONTACTTCMEMO,
              name=u'tcMemo', parent=self, pos=wx.Point(160, 120),
              size=wx.Size(320, 112), style=wx.TE_MULTILINE, value=u'')

        self.btnOk = wx.Button(id=wxID_DLGEDITORCONTACTBTNOK,
              label=u'\u786e\u5b9a', name=u'btnOk', parent=self,
              pos=wx.Point(120, 288), size=wx.Size(75, 24), style=0)
        self.btnOk.Bind(wx.EVT_BUTTON, self.OnBtnOkButton,
              id=wxID_DLGEDITORCONTACTBTNOK)

        self.btnCancel = wx.Button(id=wxID_DLGEDITORCONTACTBTNCANCEL,
              label=u'\u53d6\u6d88', name=u'btnCancel', parent=self,
              pos=wx.Point(336, 288), size=wx.Size(75, 24), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_DLGEDITORCONTACTBTNCANCEL)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.curObj = None

    def getContactObj(self):
        return self.curObj
        
    def OnBtnOkButton(self, event):
        if (self.tcName.GetValue() == ''):
            dlg = wx.MessageDialog(self, u'必须设置联系人姓名', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        peerObj = self.GetParent().getSelectPeer()
        peerId = peerObj.getValue(peerObj.COL_ID)
        
        cls = CDataCustomerContact
        data = {cls.iId:cls.newAutoIncrId(),
                cls.iName:self.tcName.GetValue(),
                cls.iPeerId:peerId,
                cls.iPhone:self.tcPhone.GetValue(),
                cls.iMemo:self.tcMemo.GetValue()}
        
        if (self.curObj is not None):
            self.curObj.setMulFieldVal(data)
            self.curObj.update()
        else:
            self.curObj = cls.factory()
            self.curObj.setMulFieldVal(data)
            self.curObj.insert()

        self.EndModal(wx.ID_OK)

    def OnBtnCancelButton(self, event):
        self.EndModal(wx.ID_CANCEL)
